package com.nemodynamic.cattivial;

import java.util.Random;

import com.nemodynamic.cattivial.beansElement.Question;

import net.sourceforge.jeval.Evaluator;

public class QuestionFactory {
	private static final String TAG = "QuestionFactory";

	public static Question createQuestion(int level) {
		try {
			int results[] = new int[3];
			String question = "";
			switch (level) {
			case 1:
				question = generateLevel1Question();
				break;

			default:
				break;
			}
			if (!question.isEmpty()) {
				Evaluator evaluator = new Evaluator();
				Integer result = Double.valueOf(evaluator.evaluate(question)).intValue();
				int randomMax = result + 10;
				results[0] = result + new Random().nextInt(Math.abs(randomMax));
				results[1] = result + new Random().nextInt(Math.abs(randomMax));
				results[2] = result + new Random().nextInt(Math.abs(randomMax));
				results[new Random().nextInt(3)] = result;
				return new Question(question, results, result, 10);
			}else{
				return null;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	private static String generateLevel1Question() {
		Integer x = Integer.valueOf(new Random().nextInt(10));
		Integer y = Integer.valueOf(new Random().nextInt(10));
		String operator[] = { "+", "-", "*" };
		return new String(x + " " + operator[(new Random()).nextInt(2)] + " " + y);

	}
}
